package cn.jiyun.utils;

import lombok.Data;

import java.util.HashMap;
import java.util.Map;

@Data
public class Result {
    /**
     * 标识
     */
    private Boolean success;
    /**
     * 状态码
     */
    private Integer code;
    /**
     * 传递信息
     */
    private String message;
    /**
     * 传递数据
     */
    private Map<String, Object> data = new HashMap<>();

    /**
     * 通过方法
     *
     * @return Result
     */
    public static Result ok() {
        Result r = new Result();
        r.setSuccess(true);
        r.setCode(1);
        r.setMessage("成功");
        return r;
    }

    /**
     * 未通过方法
     *
     * @return Result
     */
    public static Result error() {
        Result r = new Result();
        r.setSuccess(false);
        r.setCode(2);
        r.setMessage("失败");
        return r;
    }

    public Result success(Boolean success) {
        this.success = success;
        return this;
    }

    public Result code(Integer code) {
        this.code = code;
        return this;
    }

    public Result message(String message) {
        this.message = message;
        return this;
    }

    public Result data(String key, Object value) {
        this.data.put(key, value);
        return this;
    }

}
